const express = require("express");
const { login, sign } = require("../../authController.cjs");
var route = express.Router();

//login and send token
route.post("/login", async (req, res) => {
  let result = await login(req.body.user);
  console.log("result:", result);
  if (result.ok) {
    //res.status(200).json(result);
    // return token
    result.token = sign(result);
    res.status(200).json(result);
  } else {
    res.status(420).json(result);
  }
});

module.exports = route;
